<?php
$SITEROOT = '../';
include_once($SITEROOT . 'assets/snippets/shoppingCart/dbconfig.inc.php');
include_once($SITEROOT . 'assets/snippets/shoppingCart/kiwee.class.php');

$kiwee = new Kiwee();

if(IN_MANAGER_MODE!="true") die('<b>' . $_lang['kiwee_include_order_error'] . '</b>');
if ($_SESSION['mgrPermissions']['settings'] != "1") { echo 'Insufficient permissions for this module.'; exit; }

foreach ($_POST as $k => $v) {
	switch ($k) {
		case 'error_page':
		case 'unauthorized_page':
		if (trim($v) == '' || !is_numeric($v)) {
			$v = $_POST['site_start'];
		}
		break;
		default:
		break;
	}
	
	$v = is_array($v) ? implode(",", $von ) : $v;
	if ($k == 'manager_lang_attribute' && trim($v) == '') $v = 'en';
	// Store Current Options so we can roll back if it doesn't work
	$sql = "SELECT * from " . $kiwee->config['fpx'] . 'config_values' . " where optname=\"$k\"";
	$res = mysql_query($sql) or die ("COULD NOT RETRIEVE CURRENT OPTION VALUE for $k: " . mysql_error());
		
	// Insert values
	$numrows = mysql_num_rows($res);
	if ($numrows > 0){
		$sql = "UPDATE " . $kiwee->config['fpx'] . 'config_values' . " SET optval='" . mysql_escape_string($v) . "' where optname=\"$k\"";
	} else {
		$sql = "INSERT INTO " . $kiwee->config['fpx'] . 'config_values' . " (optname, optval) VALUES ('" . mysql_escape_string($k) . "', '" . mysql_escape_string($v) . "')";	
	}
	
	if(!@$rs = mysql_query($sql)) {
		echo "Failed to update setting value!";
		exit;
	}
}

// Reset Template Pages - by Raymond
if (isset($_POST['reset_template'])) {
	$template = $_POST['default_template'];	
	$oldtemplate = $_POST['old_template'];
	$tbl = $dbase.".`".$table_prefix."site_content`";
	$reset = $_POST['reset_template'];
	if($reset==1) mysql_query("UPDATE $tbl SET template = '$template' WHERE type='document'");
	else if($reset==2) mysql_query("UPDATE $tbl SET template = '$template' WHERE template = $oldtemplate");	
}
// Reset Template Pages - by Raymond

// empty cache
$_SESSION['mgrRefreshTheme'] = 1;			
$header = "Location: index.php?a=409";
header($header);

?>
